<template>
  <!-- 定期执行 -->
  <div class="crontabdom">
    <div class="crontabdom-con">
      <div class="crontabdom-item" v-for="(item, index) in crontabdomdata" :key="index">
        <div>执行日期：</div>
        <div>
          <el-date-picker v-model="crontabdomdata[index]" type="date" placeholder="选择日期"></el-date-picker>
        </div>
        <div>
          <span @click="add(index)" class="iconfont iconxinzeng"></span>
          <span @click="dele(index)" class="iconfont iconshanchu"></span>
        </div>
      </div>
    </div>
    <div class="task-newAddm-btn">
      <el-button type="primary" @click="next" class="centerbox">任务下发</el-button>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Prop } from "vue-property-decorator";
import time from "@/utils/time"
@Component
export default class crontabdom extends Vue {
  @Prop() datas!: any[];
  crontabdomdata = [""];
  add() {
    this.crontabdomdata.push("");
  }
  dele(index: number) {
    if (this.crontabdomdata.length == 1) {
      this.$message({
        type: "warning",
        message: "已经是最后一项了",
      });
    } else {
      this.crontabdomdata.splice(index, 1);
    }
  }
  // 定期执行的下发
  next() {
    let timedata = this.crontabdomdata;
    if (timedata.length > 0) {
      let timelist
      timedata.map(k=>{
        k=time(k)
        return k
      })
      console.log(this.datas);
      
      let params = {
        czzt: "dq",
        bdzid: this.datas[0].BDZID,
        rwid: this.datas[0].RWID,
        xjlx: this.datas[0].XJLX,
        dq: timedata,
        sendType: "dq",
      };

      (this as any).$services
        .xzrwRwxfButton({ data: { xzrwParam: params },
          method: "post",
          postparams: true, })
        .then((result: any) => {
          if (result.data) {
            this.$message({
              type: "success",
              message: "下发成功!",
            });
            this.$emit("close");
          }
        })
        .catch((err: object) => {
          console.log(err);
          this.$message({
            type: "warning",
            message: "下发失败",
          });
        });
    } else {
      this.$message({
        type: "warning",
        message: "请选择日期",
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.crontabdom {
  width: 100%;
  height: 450px;

  .task-newAddm-btn {
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }
  &-item {
    display: flex;
    justify-content: center;
    margin: 0.2rem 0;
    > div {
      line-height: 0.38rem;
      &:nth-child(3) {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 1rem;
        .iconfont {
          font-size: 0.24rem;
          cursor: pointer;
        }
      }
    }
  }
  &-con {
    height: 400px;
    overflow-y: auto;
  }
}
</style>

